#!/usr/bin/python
#coding:utf-8 
import os,sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))   
sys.path.append(BASE_DIR)
import platform
from Commons.Mkdir import mkdir
from  Util.jarProjectUtil import JarProjectUtil
pathUtil=JarProjectUtil().project_root_path()
class FilePath():
    def __init__(self,folderPath):
        self.folderPath=folderPath
        

    def environment(self):
        """ 判断什么环境下
        windows 1
        linux 2
        mac 3
        """
        # 查看系统类型
        platform_ = platform.system()
        platformenv =1  # 默认0 如果读不到,默认是在windows 环境下
        if platform_ == "Windows":

            platformenv = 1 #windows 1
        elif platform_ == "Linux":
            platformenv = 2 #linux 2
        elif platform_ == "Mac":
            platformenv = 3  # mac 3
        return  platformenv

    def path(self): 
        env=self.environment() 
        if self.folderPath is  None: 
            raise self.ConstCaseError("请传入文件夹路径,  项目/xxx文件夹  ")  
        if(env==1):
            folderPath=self.folderPath.replace("/","\\")
            # print(pathUtil+folderPath)
            isok,msg=mkdir(pathUtil+folderPath)
            if not isok and msg!="":
                print("创建文件夹失败,请检查是否有此文件夹  ===>",pathUtil+folderPath) 
            return  pathUtil+self.folderPath
        if(env==2):
            folderPath=self.folderPath.replace("/","/")
            isok,msg=mkdir(pathUtil+folderPath)
            if not isok and msg!="":
                print("创建文件夹失败,请检查是否有此文件夹  ===>",pathUtil+folderPath) 
            return  pathUtil+folderPath
        if(env==3): 
            folderPath=self.folderPath.replace("/","/")
            isok,msg=mkdir(pathUtil+folderPath)
            if not isok and msg!="":
                print("创建文件夹失败,请检查是否有此文件夹  ===>",pathUtil+folderPath) 
            return  pathUtil+folderPath
        mkdir(pathUtil+self.folderPath)
        return  pathUtil+self.folderPath

    # def savePath(self):
    #     """ 解析好的图存放路径
    #     E:\Captcha\priject\Captcha\static
    #      """
    #     t = time.time()
    #     pathName=str(round(t * 1000000))
    #     env=self.environment()
    #     if(env==1):
    #         mkdir(os.path.abspath('./')+"\\static\\common\\")
    #         return  (os.path.abspath('./')+"\\static\\common\\",pathName)
    #     if(env==2or env==3):
    #         mkdir(os.path.abspath('./')+"/static/common/")
    #         return  (os.path.abspath('./')+"/static/common/",pathName)
    #     mkdir(os.path.abspath('./')+"\\static\\common\\")
    #     return  (os.path.abspath('./')+"\\static\\common\\",pathName)


 
# Todo 测试 是否 符合要求
# if __name__=="__main__":
#     filename=FilePath()
#     s =filename.path()
#     print(s)